This is a good example of not adapting an existing script. You got hung up with trying to select a row. But that's irrelevant, because you always want to deal with a table's first and second rows. So you need to get a reference to a table, insert two rows after the second row, then duplicate the cells contents of the first row to the third row, and the contents of the cells in the second row to those in the fourth one.
Here's a fairly naive script that follows that line.
// Select an insertion point anywhere in the table
// (i.e. click anywhere in the table)
table = app.selection[0].parent.parent;
// Add a row after the first row
table.rows.add (LocationOptions.AFTER, table.rows[1]);
// Duplicate the contents of the cells in the first row
// to the cells in the third row
cells1 = table.rows[0].cells;
cells2 = table.rows[2].cells;
for (i = 0; i < cells1.length; i++) {
cells1[i].texts[0].duplicate (
LocationOptions.AFTER,
cells2[i].texts[0].insertionPoints[0]
)
}
// Add a row after the third row
table.rows.add (LocationOptions.AFTER, table.rows[2]);
// Duplicate etc.
cells1 = table.rows[1].cells;
cells2 = table.rows[3].cells;
for (i = 0; i < cells1.length; i++) {
cells1[i].texts[0].duplicate (
LocationOptions.AFTER,
cells2[i].texts[0].insertionPoints[0]
)
}
... View more